﻿@using System.Data;

@using UtilsORM.MySqlData;
@using GatewayServer.Common;

@using UtilsBase;
@using UtilsBase;

@{
    ViewBag.PageTitle = "洪峰智能";

    Layout = "~/Views/Shared/PageTemplate.cshtml";
}

<script>
    $(document).ready(function () {
        getGateWay();
        $("#hid_l_d_guid").val('@(((iot_device_command_log)ViewData["reqobj"]).l_d_guid)');
        $("#d_code").val('@(((iot_device)ViewData["reqdevice"]).d_code)');

    });
    function getGateWay() {
        $("#l_d_guid").empty();
        $("#l_d_guid").append("<option value=''  selected='selected'>请选择</option>");
        $.post("getGateWayList", { "flag": Math.random() }, function (result) {
            var myobj = (result.data);
            for (var i = myobj.length - 1; i >= 0; i--) {
                $("#l_d_guid").prepend("<option value='" + myobj[i].d_guid + "'>" + myobj[i].d_code + "-" + myobj[i].d_name + "</option>")
            }

            for (var i = 0; i < document.getElementById("l_d_guid").options.length; i++) {
                if (document.getElementById("l_d_guid").options[i].value == $("#hid_l_d_guid").val()) {
                    document.getElementById("l_d_guid").options[i].selected = true;
                    break;
                }
                else {
                    document.getElementById("l_d_guid").options[i].selected = false;

                }
            }


        });
    }
</script>

<div id="saper-container">
    <form id="searchForm" name="searchForm" action="list" method="post">
        <div id="saper-hd"></div>
        <div id="saper-bd">
            <div class="subfiled clearfix">
                <h2>指令记录</h2>
            </div>
            <div class="subfiled-content">
                <div class="search-box clearfix">
                    <div class="kv-item clearfix">
                        <label>设备编码：</label>
                        <div class="kv-item-content">
                            <input type="text" id="d_code" value="" name="d_code" placeholder="设备编码" />
                        </div>
                    </div>
                    <div class="kv-item clearfix">
                        <label><span class="impInfo">*</span>网关：</label>
                        <div class="kv-item-content">
                            <select id="l_d_guid" name="l_d_guid" style="width:130px;">
                                <option value="">请选择</option>
                            </select>
                            <input type="hidden" name="hid_l_d_guid" id="hid_l_d_guid" value="" />
                        </div>
                    </div>
                    <div class="kv-item clearfix">
                        <label>设备名称：</label>
                        <div class="kv-item-content">
                            <input type="text" id="name" value="@Model.name" name="name" placeholder="名称" />
                        </div>
                    </div>
                    <a href="javascript:;" id="but_Search" name="but_Search" class="sapar-btn sapar-btn-recom query-btn">查询</a>
                </div>
                <!--表格开始-->
                <div class="table">
                    <!--表格操作-->
                    <!--表格具体内容-->
                    <div class="table-box">
                        <table>
                            <thead>
                                <tr>
                                    <th>序号</th>
                                    <th>设备名称</th>
                                    <th>设备编码</th>
                                    <th>key</th>
                                    <th>指令</th>
                                    <th>网关编码</th>
                                    <th>协议</th>
                                    <th>设备型号编号</th>
                                    <th>来源</th>
                                    <th>备注</th>
                                    <th>时间</th>
                                </tr>
                            </thead>
                            <tbody>

                                @{
                                    int rowcount = 0; string result = "";
                                }
                                @foreach (DataRow item in (ViewData["DataList"] as DataTable).Rows)
                                {
                                    rowcount = rowcount + 1;
                                    <tr @Html.Raw(rowcount % 2 == 0 ? "style='background-color:#EFF6FA';" : "") id="tr_@rowcount" onclick="selectTr('@rowcount','15','@item["l_id"]')">


                                        <td style="width:50px;">@(rowcount + ((int)ViewBag.PageIndex - 1) * (int)ViewBag.PageSize)</td>
                                        <td>@item["l_device_remark"]</td>
                                        <td>@item["d_code"]</td>
                                        <td>@item["l_key"]</td>
                                        <td>@item["l_name"]</td>
                                        <td>@item["l_gateway_code"]</td>
                                        <td>@item["l_agreement_type"]</td>
                                        <td>@item["l_device_model_code"]</td>
                                        <td>@item["l_source"]</td>
                                        <td>@item["l_status_remark"]</td>
                                        <td>@(UtilsDateTime.getFormatTime(item["l_add_time"].ToString()))</td>
                                    </tr>
                                    <tr>
                                        <td></td>
                                        <td colspan="9"><div style='background-color:#fbf9eb;color:#959597;border-radius:5px;'>@item["l_return_msg"]</div></td>
                                    </tr>
                                }
                                @if (rowcount < 1)
                                {
                                    <tr class="no-data"><td colspan="11" style="text-align:center">暂时没有数据</td></tr>
                                }
                            </tbody>
                        </table>
                        @Html.Raw(new GatewayServer.Common.PageHelper().GetPageHtml((int)ViewBag.RecordCount, (int)ViewBag.PageIndex, (int)ViewBag.PageCount))
                    </div>
                </div><!--表格结束-->
            </div>
        </div>
        <div id="saper-ft"></div>
    </form>
</div>
